home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
manchester
/
2.2
/
Interface-Joysticks.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
69KB
|
2,149 lines
" NAME Interface-Joysticks
AUTHOR tph@cs.man.ac.uk
FUNCTION mouse becomes a joystick; many eg's
ST-VERSIONS 2.3
PREREQUISITES
CONFLICTS
DISTRIBUTION world
VERSION 1.1
DATE 22 Jan 1989
SUMMARY Interface-Joysticks
contains several MVC components to mimic
various joysticks, which can be moved by moving the mouse around.
It is intended as a small part for larger MVC applications
(especially games!!). It is modelled closely on the
Switch/SwitchView stuff.
This goodie is only known to work with VI2.2 and VI2.3 images,
although it could probably be made to work with other versions
quite easily.
The current version is dated 6/1/89, and has been quite extensively
reworked. A large number of examples are provided. -tph
"!
Controller subclass: #JoystickController
instanceVariableNames: 'offsize '
classVariableNames: 'DefaultOffSize '
poolDictionaries: ''
category: 'Interface-Joysticks'!
JoystickController comment:
'I am a Controller subclass intended for use with a JoystickView and an
instance of a subclass of Joystick. I operate only on ''red button'' presses.
I have just one instance variable:
offsize <Number>, representing the ''dead'' area in the center of the Joystick.'!
!JoystickController methodsFor: 'initialize-release'!
initialize
"Initialize instance variable."
super initialize.
offsize _ DefaultOffSize! !
!JoystickController methodsFor: 'accessing'!
offSize
"Answer with the value of the current dead region."
^offsize!
offSize: aNumber
"Set the value of the current dead region."
offsize _ aNumber! !
!JoystickController methodsFor: 'basic control sequence'!
controlInitialize
"When controller started, make the cursor a crosshair."
Cursor crossHair show!
controlTerminate
"When control released, restore the cursor and display."
Cursor normal show.
model clear! !
!JoystickController methodsFor: 'control defaults'!
controlActivity
"If the red button is pressed, move the joystick about."
sensor keyboardPressed ifTrue: [
model moveCharacter: sensor keyboard].
sensor redButtonPressed ifTrue: [
self movementAction.
sensor waitNoButton.
model return]!
movementAction
"If the cursor is close to the center of the displayed view, then
center the model. Otherwise, move the model."
| center point |
center _ view insetDisplayBox center.
(center dist: sensor cursorPoint) < offsize
ifTrue: [model return]
ifFalse: [model movePoint: sensor cursorPoint - center]! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
JoystickController class
instanceVariableNames: ''!
!JoystickController class methodsFor: 'class initialization'!
initialize
"Initialize class variables."
"JoystickController initialize."
DefaultOffSize _ 10. "Maximum distance from center
of view where no action takes place."! !
JoystickController initialize!
View subclass: #JoystickView
instanceVariableNames: ''
classVariableNames: 'DiagonalOffForm DownForm DownLeftForm DownRightForm FourWayOffForm HorizOffForm LeftForm RightForm UpForm UpLeftForm UpRightForm VertOffForm '
poolDictionaries: ''
category: 'Interface-Joysticks'!
JoystickView comment:
'I am a View subclass intended for use with various Joystick subclasses. I
know how to display various ''joystick-like'' forms. The actual forms used
are retained as class variables:
DiagonalOffForm
DownForm
DownLeftForm
DownRightForm
FourWayOffForm
HorizOffForm
LeftForm
RightForm
UpForm
UpLeftForm
UpRightForm
VertOffForm
See the comment in JoystickView class|initialize to view these forms.
'!
!JoystickView methodsFor: 'initialize-release'!
initialize
"Ensure that the inside colour is white by default."
super initialize.
self insideColor: Form white.! !
!JoystickView methodsFor: 'controller access'!
defaultControllerClass
"The default controller is JoystickController."
^JoystickController! !
!JoystickView methodsFor: 'displaying'!
displayDown
"Display the down form."
DownForm displayAt:
self insetDisplayBox center - DownForm boundingBox center!
displayLeft
"Display the left form."
LeftForm displayAt:
self insetDisplayBox center - LeftForm boundingBox center!
displayLeftDown
"Display the left-and-down form."
DownLeftForm displayAt:
self insetDisplayBox center - DownLeftForm boundingBox center!
displayLeftUp
"Display the left-and-up form."
UpLeftForm displayAt:
self insetDisplayBox center - UpLeftForm boundingBox center!
displayOff
"Display the off form."
model class == TwoWayHorizJoystick ifTrue: [
HorizOffForm displayAt:
self insetDisplayBox center - HorizOffForm boundingBox center.
^self].
model class == TwoWayVertJoystick ifTrue: [
VertOffForm displayAt:
self insetDisplayBox center - VertOffForm boundingBox center.
^self].
model class == DiagonalJoystick ifTrue: [
DiagonalOffForm displayAt:
self insetDisplayBox center - DiagonalOffForm boundingBox center.
^self].
FourWayOffForm displayAt:
self insetDisplayBox center - FourWayOffForm boundingBox center.!
displayRight
"Display the right form."
RightForm displayAt:
self insetDisplayBox center - RightForm boundingBox center!
displayRightDown
"Display the right-and-down form."
DownRightForm displayAt:
self insetDisplayBox center - DownRightForm boundingBox center!
displayRightUp
"Display the right-and-up form."
UpRightForm displayAt:
self insetDisplayBox center - UpRightForm boundingBox center!
displayUp
"Display the up form."
UpForm displayAt:
self insetDisplayBox center - UpForm boundingBox center!
displayView
"Display the appropriate form for the receiver's model."
model state == #off ifTrue: [self displayOff].
model state == #up ifTrue: [self displayUp].
model state == #down ifTrue: [self displayDown].
model state == #left ifTrue: [self displayLeft].
model state == #right ifTrue: [self displayRight].
model state == #leftUp ifTrue: [self displayLeftUp].
model state == #leftDown ifTrue: [self displayLeftDown].
model state == #rightUp ifTrue: [self displayRightUp].
model state == #rightDown ifTrue: [self displayRightDown].! !
!JoystickView methodsFor: 'updating'!
update: aParameter
"Ignore aParameter, and redisplay the receiver."
aParameter == #error ifTrue: [self flash] ifFalse: [self display]! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
JoystickView class
instanceVariableNames: ''!
!JoystickView class methodsFor: 'class initialization'!
initialize
"Initialize all the forms used for displaying."
"JoystickView initialize."
self initializeOffForms.
self initializeUpForm.
self initializeUpRightForm.
self initializeOtherForms
"(Quadrangle new region: (30@80 extent: 440@140))
borderWidth: 2;
insideColor: Form gray;
display.
JoystickView fourWayOffForm displayAt: 50@100.
JoystickView diagonalOffForm displayAt: 100@100.
JoystickView horizOffForm displayAt: 150@100.
JoystickView vertOffForm displayAt: 200@100.
JoystickView upForm displayAt: 250@100.
JoystickView rightForm displayAt: 300@100.
JoystickView downForm displayAt: 350@100.
JoystickView leftForm displayAt: 400@100.
JoystickView upRightForm displayAt: 250@150.
JoystickView downRightForm displayAt: 300@150.
JoystickView upLeftForm displayAt: 350@150.
JoystickView downLeftForm displayAt: 400@150."! !
!JoystickView class methodsFor: 'class access'!
diagonalOffForm
"Answer with the form displayed for no movement, for diagonal
(four-way) models."
^DiagonalOffForm!
downForm
"Answer with the form displayed for downwards movement."
^DownForm!
downLeftForm
"Answer with the form displayed for down-and-left movement."
^DownLeftForm!
downRightForm
"Answer with the form displayed for down-and-right movement."
^DownRightForm!
fourWayOffForm
"Answer with the form displayed for no movement, for four-way models."
^FourWayOffForm!
horizOffForm
"Answer with the form displayed for no movement, for horizontal 2-way models."
^HorizOffForm!
leftForm
"Answer with the form displayed for leftwards movement."
^LeftForm!
rightForm
"Answer with the form displayed for rightwards movement."
^RightForm!
upForm
"Answer with the form displayed for upwards movement."
^UpForm!
upLeftForm
"Answer with the form displayed for up-and-left movement."
^UpLeftForm!
upRightForm
"Answer with the form displayed for up-and-right movement."
^UpRightForm!
vertOffForm
"Answer with the form displayed for no movement, for vertical 2-way models."
^VertOffForm! !
!JoystickView class methodsFor: 'private'!
initializeDiagonalOffForm
"Initialize the default form used to display in the off position,
for 4-way (diagonal) joysticks."
DiagonalOffForm _ OpaqueForm figure: (Form
extent: 50@50
fromArray: # (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 511 65535 65504 0 384 0 96 0 320 0 160 0 288 0 288 0 272 0 544 0 264 0 1056 0 260 192 2080 0 258 1848 4128 0 257 6150 8224 0 256 40961 16416 0 256 16384 32800 0 256 48959 16416 0 257 15903 8224 0 257 15903 8224 0 258 16191 4128 0 258 16383 4128 0 258 10233 4128 0 260 1008 2080 0 260 1008 2080 0 258 10233 4128 0 258 16383 4128 0 258 16319 4128 0 257 15903 8224 0 257 15903 8224 0 256 48959 16416 0 256 16384 32800 0 256 40961 16416 0 257 6150 8224 0 258 1848 4128 0 260 192 2080 0 264 0 1056 0 272 0 544 0 288 0 288 0 320 0 160 0 384 0 96 0 511 65535 65504 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
offset: 0@0) shape: (Form
extent: 50@50
fromArray: # (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
offset: 0@0)!
initializeFourWayOffForm
"Initialize the default form used to display in the off position,
for 4-way joysticks."
FourWayOffForm _ OpaqueForm figure: (Form
extent: 50@50
fromArray: #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 511 65535 65504 0 384 0 96 0 320 0 160 0 288 0 288 0 272 0 544 0 264 0 1056 0 260 192 2080 0 258 1848 4128 0 257 6150 8224 0 256 41153 16416 0 256 16864 32800 0 256 33776 16416 0 257 2040 8224 0 257 480 8224 0 258 4578 4128 0 258 12771 4128 0 258 32767 36896 0 260 65535 51232 0 260 65535 51232 0 258 29155 36896 0 258 12771 4128 0 258 4578 4128 0 257 480 8224 0 257 2040 8224 0 256 33776 16416 0 256 16864 32800 0 256 41153 16416 0 257 6150 8224 0 258 1848 4128 0 260 192 2080 0 264 0 1056 0 272 0 544 0 288 0 288 0 320 0 160 0 384 0 96 0 511 65535 65504 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
offset: 0@0) shape: (Form
extent: 50@50
fromArray: #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
offset: 0@0)!
initializeHorizOffForm
"Initialize the default form used to display in the off position,
for 2-way horizontal joysticks."
HorizOffForm _ OpaqueForm figure: (Form
extent: 50@50
fromArray: # (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 511 65535 65504 0 384 0 96 0 320 0 160 0 288 0 288 0 272 0 544 0 264 0 1056 0 260 192 2080 0 258 1848 4128 0 257 6150 8224 0 256 40961 16416 0 256 16384 32800 0 256 32768 16416 0 257 1032 8224 0 257 3084 8224 0 258 7182 4128 0 258 15375 4128 0 258 32767 36896 0 260 65535 51232 0 260 65535 51232 0 258 32767 36896 0 258 15375 4128 0 258 7182 4128 0 257 3084 8224 0 257 1032 8224 0 256 32768 16416 0 256 16384 32800 0 256 40961 16416 0 257 6150 8224 0 258 1848 4128 0 260 192 2080 0 264 0 1056 0 272 0 544 0 288 0 288 0 320 0 160 0 384 0 96 0 511 65535 65504 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
offset: 0@0) shape: (Form
extent: 50@50
fromArray: # (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
offset: 0@0)!
initializeOffForms
"Initialize the default forms used to display in the off position."
self initializeFourWayOffForm.
self initializeDiagonalOffForm.
self initializeHorizOffForm.
self initializeVertOffForm!
initializeOtherForms
"Initialize the other three displayable forms, by rotating
the existing 'up' form suitably."
RightForm _ OpaqueForm
figure: (UpForm figure rotateBy: 1)
shape: (UpForm shape rotateBy: 1).
DownForm _ OpaqueForm
figure: (UpForm figure rotateBy: 2)
shape: (UpForm shape rotateBy: 2).
LeftForm _ OpaqueForm
figure: (UpForm figure rotateBy: 3)
shape: (UpForm shape rotateBy: 3).
DownRightForm _ OpaqueForm
figure: (UpRightForm figure rotateBy: 1)
shape: (UpRightForm shape rotateBy: 1).
DownLeftForm _ OpaqueForm
figure: (UpRightForm figure rotateBy: 2)
shape: (UpRightForm shape rotateBy: 2).
UpLeftForm _ OpaqueForm
figure: (UpRightForm figure rotateBy: 3)
shape: (UpRightForm shape rotateBy: 3).!
initializeUpForm
"Initialize the default form used to display in the up position."
UpForm _ OpaqueForm figure: (Form
extent: 50@50
fromArray: #(0 192 0 0 0 1848 0 0 0 6150 0 0 0 8385 0 0 0 16864 32768 0 0 33776 16384 0 1 2040 8192 0 511 4092 16352 0 386 8190 4192 0 322 480 4256 0 290 480 4384 0 276 480 2592 0 268 480 3104 0 262 480 6176 0 258 480 4128 0 258 480 4128 0 257 0 8224 0 257 0 8224 0 256 32768 16416 0 256 16384 32800 0 256 8193 32 0 256 6150 32 0 256 7998 32 0 256 7374 32 0 256 7710 32 0 256 7710 32 0 256 7710 32 0 256 7998 32 0 256 7998 32 0 256 8190 32 0 256 8190 32 0 256 8193 32 0 256 16384 32800 0 256 32768 16416 0 257 0 8224 0 258 0 4128 0 260 0 2080 0 264 0 1056 0 272 0 544 0 288 0 288 0 320 0 160 0 384 0 96 0 511 65535 65504 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
offset: 0@0) shape: (Form
extent: 50@50
fromArray: #(0 192 0 0 0 2040 0 0 0 8190 0 0 0 16383 0 0 0 32767 32768 0 0 65535 49152 0 1 65535 57344 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
offset: 0@0)!
initializeUpRightForm
"Initialize the default form used to display in the up-and-right position."
UpRightForm _ OpaqueForm figure: (Form
extent: 50@50
fromArray: # (0 0 1536 0 0 0 14784 0 0 0 49200 0 0 1 8 0 0 2 4 0 0 4 2 0 0 8 8177 0 511 65528 4081 0 384 16 2032 32768 320 16 1008 32768 288 16 2032 32768 272 32 4080 16384 264 32 8048 16384 260 16 15920 32768 258 16 31760 32768 257 16 30720 32768 256 32808 28673 0 256 16424 1 0 256 8260 2 0 256 8130 4 0 256 8065 8 0 256 8064 49200 0 256 7936 14816 0 256 7936 50720 0 256 7683 32 0 256 7694 32 0 256 7230 32 0 256 7422 32 0 256 8190 32 0 256 8190 32 0 256 8190 32 0 256 8193 32 0 256 16384 32800 0 256 32768 16416 0 257 0 8224 0 258 0 4128 0 260 0 2080 0 264 0 1056 0 272 0 544 0 288 0 288 0 320 0 160 0 384 0 96 0 511 65535 65504 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
offset: 0@0) shape: (Form
extent: 50@50
fromArray: # (0 0 1536 0 0 0 16320 0 0 0 65520 0 0 1 65528 0 0 3 65532 0 0 7 65534 0 0 15 65535 0 511 65535 65535 0 511 65535 65535 32768 511 65535 65535 32768 511 65535 65535 32768 511 65535 65535 49152 511 65535 65535 49152 511 65535 65535 32768 511 65535 65535 32768 511 65535 65535 32768 511 65535 65535 0 511 65535 65535 0 511 65535 65534 0 511 65535 65532 0 511 65535 65528 0 511 65535 65520 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
offset: 0@0)!
initializeVertOffForm
"Initialize the default form used to display in the off position,
for 2-way vertical joysticks."
VertOffForm _ OpaqueForm figure: (Form
extent: 50@50
fromArray: # (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 511 65535 65504 0 384 0 96 0 320 0 160 0 288 0 288 0 272 0 544 0 264 0 1056 0 260 192 2080 0 258 1848 4128 0 257 6150 8224 0 256 41153 16416 0 256 16864 32800 0 256 33776 16416 0 257 2040 8224 0 257 4092 8224 0 258 8190 4128 0 258 480 4128 0 258 480 4128 0 260 480 2080 0 260 480 2080 0 258 480 4128 0 258 480 4128 0 258 8190 4128 0 257 4092 8224 0 257 2040 8224 0 256 33776 16416 0 256 16864 32800 0 256 41153 16416 0 257 6150 8224 0 258 1848 4128 0 260 192 2080 0 264 0 1056 0 272 0 544 0 288 0 288 0 320 0 160 0 384 0 96 0 511 65535 65504 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
offset: 0@0) shape: (Form
extent: 50@50
fromArray: #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 511 65535 65504 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
offset: 0@0)! !
JoystickView initialize!
Model subclass: #Joystick
instanceVariableNames: 'state '
classVariableNames: ''
poolDictionaries: ''
category: 'Interface-Joysticks'!
Joystick comment:
'I represent an abstract superclass for various joysticks. Instances of my
subclasses are intended to be used with instances of JoystickView and
JoystickController.
I have just one instance variable:
state <Symbol> representing the current state of the receiver.
"GraphHolderView
openOn: (Array
with: Joystick
with: JoystickView
with: JoystickController)
label: ''Joysticks''
format: #( horizontal)
menu: (ActionMenu labels: ''browse\inspect'' withCRs selectors: #(browse inspect))."
'!
!Joystick methodsFor: 'initialize-release'!
initialize
"Initialize the receiver's state to #off. Subclasses should include
super initialize in any re-implementation."
state _ #off! !
!Joystick methodsFor: 'dependents access'!
removeDependent: aDependent
"If aDependent is the only dependent in the list, the receiver sends
Joystick|release to try to break up possible pointer cycles."
super removeDependent: aDependent.
self dependents isEmpty ifTrue: [self release]! !
!Joystick methodsFor: 'testing'!
isDown
"Answer whether the receiver is down."
^state == #down!
isDownLeft
"Answer whether the receiver is down-and-left."
^state == #leftDown!
isDownRight
"Answer whether the receiver is down-and-right."
^state == #rightDown!
isLeft
"Answer whether the receiver is left."
^state == #left!
isOff
"Answer whether the receiver is off."
^state == #off!
isOn
"Answer whether the receiver is on."
^(state ~~ #off)!
isRight
"Answer whether the receiver is right."
^state == #right!
isUp
"Answer whether the receiver is up."
^state == #up!
isUpLeft
"Answer whether the receiver is up-and-left."
^state == #leftUp!
isUpRight
"Answer whether the receiver is up-and-right."
^state == #rightUp! !
!Joystick methodsFor: 'state changes'!
clear
"Set the state of the receiver to 'off'. If the state of the
receiver was not previously 'off', then 'self change' is sent.
No actions are executed."
self isOn ifTrue: [state _ #off. self changed]!
moveAngle: anAngle
"The angle between the joystick center and the cursor position is
anAngle, relative to the x-axis. Move appropriately."
self subclassResponsibility!
moveCharacter: aCharacter
"Execute the block selected by aCharacter (from the user). The default
behaviour is to signal an error."
self changed: #error!
movePoint: aPoint
"The distance between the joystick center and the cursor position is
given by aPoint. Perform the appropriate state changes."
self moveAngle: aPoint theta radiansToDegrees!
return
"Set the state of the receiver to #off and perform the appropriate
off action. If the receiver was not previously off, update any dependents."
self subclassResponsibility!
state
"Answer with the current state of the receiver."
^state! !
!Joystick methodsFor: 'action'!
doAction: aBlock
"Execute aBlock if it is non-nil."
aBlock notNil ifTrue: [aBlock value]! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
Joystick class
instanceVariableNames: ''!
!Joystick class methodsFor: 'instance creation'!
new
"Answer an instance of me such that all actions are set to nil
('no action'), and the state is set to #off."
^super new initialize! !
JoystickController subclass: #RepeatJoystickController
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Interface-Joysticks'!
RepeatJoystickController comment:
'I am a subclass of JoystickController who knows how to repeatedly
signal the model when the red button is pressed.'!
!RepeatJoystickController methodsFor: 'control defaults'!
controlActivity
"If the red button is pressed, move the joystick about."
sensor keyboardPressed ifTrue: [
model moveCharacter: sensor keyboard].
[sensor redButtonPressed] whileTrue: [self movementAction].
model return! !
Joystick subclass: #TwoWayVertJoystick
instanceVariableNames: 'upOnAction upOffAction downOnAction downOffAction upChar downChar '
classVariableNames: ''
poolDictionaries: ''
category: 'Interface-Joysticks'!
TwoWayVertJoystick comment:
'I represent a Joystick which can move only up and down. I have four
instance variables, which are blocks which execute whenever the state
changes:
onUpAction <BlockContext> or nil
offUpAction <BlockContext> or nil
onDownAction <BlockContext> or nil
offDownAction <BlockContext> or nil
upChar <Character> for moving up
downChar <Character> for moving down'!
!TwoWayVertJoystick methodsFor: 'initialize-release'!
release
"Set all the actions of the receiver to nil ('no action') in order to break
possible pointer cycles. It is sent by Joystick|removeDependent: when the
last dependent has been deleted from the Joystick's list of dependents."
super release.
upOnAction _ nil.
upOffAction _ nil.
downOnAction _ nil.
downOffAction _ nil.! !
!TwoWayVertJoystick methodsFor: 'accessing'!
downChar: aCharacter
"Set the 'down' character to aCharacter."
downChar _ aCharacter!
upChar: aCharacter
"Set the 'up' character to aCharacter."
upChar _ aCharacter! !
!TwoWayVertJoystick methodsFor: 'state changes'!
goDown
"Set the state of the receiver to #down and perform the `down on'
action. If the receiver was not #down, then change any dependents."
self doAction: downOnAction.
self isDown ifFalse: [state _ #down. self changed]!
goToDown
"Return to the #off position, and then move to #down."
self return.
self goDown.!
goToUp
"Return to the #off position, and then move to #up."
self return.
self goUp.!
goUp
"Set the state of the receiver to #up and perform the `up on'
action. If the receiver was not #up, then change any dependents."
self doAction: upOnAction.
self isUp ifFalse: [state _ #up. self changed]!
moveAngle: anAngle
"The angle between the joystick center and the cursor position is
anAngle, relative to the x-axis. Move appropriately."
(anAngle between: 45 and: 135)
ifTrue: [self isDown ifTrue: [^self goDown] ifFalse: [^self goToDown]].
(anAngle between: 225 and: 315)
ifTrue: [self isUp ifTrue: [^self goUp] ifFalse: [^self goToUp]]!
moveCharacter: aCharacter
"Execute the block selected by aCharacter (from the user)."
aCharacter == upChar ifTrue: [self goUp. ^self return].
aCharacter == downChar ifTrue: [self goDown. ^self return].
super moveCharacter: aCharacter!
return
"Set the state of the receiver to #off and perform the appropriate
off action. If the receiver was not previously off, update any dependents."
self isUp ifTrue: [self doAction: upOffAction].
self isDown ifTrue: [self doAction: downOffAction].
self isOff ifFalse: [state _ #off. self changed]! !
!TwoWayVertJoystick methodsFor: 'action'!
downOffAction: aBlock
"Set the down, off action of the receiver to aBlock."
downOffAction _ aBlock fixTemps!
downOnAction: aBlock
"Set the down, on action of the receiver to aBlock."
downOnAction _ aBlock fixTemps!
upOffAction: aBlock
"Set the up, off action of the receiver to aBlock."
upOffAction _ aBlock fixTemps!
upOnAction: aBlock
"Set the up, on action of the receiver to aBlock."
upOnAction _ aBlock fixTemps! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
TwoWayVertJoystick class
instanceVariableNames: ''!
!TwoWayVertJoystick class methodsFor: 'instance creation'!
upAction: upBlock downAction: downBlock
"Answer with a new instance of the receiver, which evaluates
upBlock when moved up, and downBlock when moved down."
| temp |
temp _ super new upOnAction: upBlock.
temp downOnAction: downBlock.
^temp! !
!TwoWayVertJoystick class methodsFor: 'examples'!
example1
"Illustrates basic action of a TwoWayVertJoystick."
"TwoWayVertJoystick example1."
| j |
j _ TwoWayVertJoystick
upAction: [Transcript cr; show: 'Going up.']
downAction: [Transcript cr; show: 'Going down.'].
j goToUp.
j goToDown.
j return!
example2
"Illustrates use of TwoWayVertJoystick with simple view and normal
(non-auto-repeat) controller. No 'off' actions."
"TwoWayVertJoystick example2."
| view topView joystick |
joystick _ TwoWayVertJoystick
upAction: [Transcript cr; show: 'Going up.']
downAction: [Transcript cr; show: 'Going down.'].
view _ JoystickView new model: joystick.
topView _ StandardSystemView
model: nil
label: 'Vertical Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open!
example3
"This example uses an 'auto-repeat' controller."
"TwoWayVertJoystick example3."
| view topView joystick |
joystick _ TwoWayVertJoystick
upAction: [Transcript cr; show: 'Going up.']
downAction: [Transcript cr; show: 'Going down.'].
view _ JoystickView new
model: joystick
controller: RepeatJoystickController new.
topView _ StandardSystemView
model: nil
label: 'Vertical Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open!
example4
"This example uses an 'auto-repeat' controller, 'off' actions, and
the view has a coloured background."
"TwoWayVertJoystick example4."
| view topView joystick |
joystick _ TwoWayVertJoystick
upAction: [Transcript cr; show: 'Going up...']
downAction: [Transcript cr; show: 'Going down...'].
joystick upOffAction: [Transcript show: 'back to center'].
joystick downOffAction: [Transcript show: 'back to center'].
view _ JoystickView new
model: joystick
controller: RepeatJoystickController new.
view insideColor: Form veryLightGray.
topView _ StandardSystemView
model: nil
label: 'Vertical Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open!
example5
"Illustrates use of TwoWayVertJoystick with simple view and normal
(non-auto-repeat) controller. Uses character input ('rogue'-style)."
"TwoWayVertJoystick example5."
| view topView joystick |
joystick _ TwoWayVertJoystick
upAction: [Transcript cr; show: 'Going up.']
downAction: [Transcript cr; show: 'Going down.'].
joystick upChar: $k.
joystick downChar: $j.
view _ JoystickView new model: joystick.
topView _ StandardSystemView
model: nil
label: 'Vertical Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open! !
Joystick subclass: #ContinuousJoystick
instanceVariableNames: 'action '
classVariableNames: ''
poolDictionaries: ''
category: 'Interface-Joysticks'!
ContinuousJoystick comment:
'I am a Joystick subclass which represents continuous movement in any
direction. I have a single instance variable:
action <BlockContext>
The ''action'' Block should have one argument. When the Joystick is
moved, the action is performed with the argument being a point representing
the displacement from the center of the Joystick.
'!
!ContinuousJoystick methodsFor: 'initialize-release'!
release
"Nil out the action block, to help break up any pointer cycles."
super release.
action _ nil! !
!ContinuousJoystick methodsFor: 'testing'!
isDown
"Answer whether the receiver is down."
^state == #down!
isDownLeft
"Answer whether the receiver is down-and-left."
^state == #leftDown!
isDownRight
"Answer whether the receiver is down-and-right."
^state == #rightDown!
isLeft
"Answer whether the receiver is left."
^state == #left!
isRight
"Answer whether the receiver is right."
^state == #right!
isUp
"Answer whether the receiver is up."
^state == #up!
isUpLeft
"Answer whether the receiver is up-and-left."
^state == #leftUp!
isUpRight
"Answer whether the receiver is up-and-right."
^state == #rightUp! !
!ContinuousJoystick methodsFor: 'state changes'!
goDown
"Set the state to #down. If not already in this state, then
signal a change."
self isDown ifFalse: [
state _ #down.
self changed]!
goDownLeft
"Set the state to #leftDown. If not already in this state, then
signal a change."
self isDownLeft ifFalse: [
state _ #leftDown.
self changed]!
goDownRight
"Set the state to #rightDown. If not already in this state, then
signal a change."
self isDownRight ifFalse: [
state _ #rightDown.
self changed]!
goLeft
"Set the state to #left. If not already in this state, then
signal a change."
self isLeft ifFalse: [
state _ #left.
self changed]!
goRight
"Set the state to #right. If not already in this state, then
signal a change."
self isRight ifFalse: [
state _ #right.
self changed]!
goUp
"Set the state to #up. If not already in this state, then
signal a change."
self isUp ifFalse: [
state _ #up.
self changed]!
goUpLeft
"Set the state to #leftUp. If not already in this state, then
signal a change."
self isUpLeft ifFalse: [
state _ #leftUp.
self changed]!
goUpRight
"Set the state to #rightUp. If not already in this state, then
signal a change."
self isUpRight ifFalse: [
state _ #rightUp.
self changed]!
moveAngle: anAngle
"The angle between the joystick center and the cursor position is
anAngle, relative to the x-axis. Move appropriately."
(anAngle between: 23 and: 67) ifTrue: [^self goDownRight].
(anAngle between: 67 and: 112) ifTrue: [^self goDown].
(anAngle between: 112 and: 157) ifTrue: [^self goDownLeft].
(anAngle between: 157 and: 202) ifTrue: [^self goLeft].
(anAngle between: 202 and: 247) ifTrue: [^self goUpLeft].
(anAngle between: 247 and: 292) ifTrue: [^self goUp].
(anAngle between: 292 and: 337) ifTrue: [^self goUpRight].
self goRight!
movePoint: aPoint
"The argument aPoint represents the distance between the center to
the joystick and the current location. Evaluate the 'action' block
with aPoint as its argument."
super movePoint: aPoint.
action value: aPoint!
return
"Set the state of the receiver to #off and perform the appropriate
off action. If the receiver was not previously off, update any dependents."
self isOff ifFalse: [state _ #off. self changed]! !
!ContinuousJoystick methodsFor: 'action'!
setAction: aBlock
"Set the action to be performed to aBlock, which should have
one argument. The block argument is a point representing the
distance from the 'center' of the joystick."
action _ aBlock! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
ContinuousJoystick class
instanceVariableNames: ''!
!ContinuousJoystick class methodsFor: 'instance creation'!
action: aBlock
"Answer with a new instance of the receiver, with action given
by aBlock."
^self new setAction: aBlock! !
!ContinuousJoystick class methodsFor: 'examples'!
example1
"Illustrates use of ContinuousJoystick with simple view and normal
(non-auto-repeat) controller."
"ContinuousJoystick example1."
| view topView joystick |
joystick _ ContinuousJoystick
action: [ :point | Transcript cr; show: point printString].
view _ JoystickView new model: joystick.
topView _ StandardSystemView
model: nil
label: 'Continuous Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open!
example2
"Illustrates use of ContinuousJoystick with simple view and
auto-repeat controller."
"ContinuousJoystick example2."
| view topView joystick |
joystick _ ContinuousJoystick
action: [ :point | Transcript cr; show: point printString].
view _ JoystickView new
model: joystick
controller: RepeatJoystickController new.
topView _ StandardSystemView
model: nil
label: 'Continuous Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open!
example3
"Illustrates use of ContinuousJoystick with view and auto-repeat
controller. Uses a very small 'dead region' size. The view has a coloured
background."
"ContinuousJoystick example3."
| view topView joystick |
joystick _ ContinuousJoystick
action: [ :point | Transcript cr; show: point printString].
view _ JoystickView new
model: joystick
controller: (RepeatJoystickController new offSize: 1).
view insideColor: Form veryLightGray.
topView _ StandardSystemView
model: nil
label: 'Continuous Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open! !
Joystick subclass: #TwoWayHorizJoystick
instanceVariableNames: 'leftOnAction leftOffAction rightOnAction rightOffAction leftChar rightChar '
classVariableNames: ''
poolDictionaries: ''
category: 'Interface-Joysticks'!
TwoWayHorizJoystick comment:
'I represent a Joystick which can move only left and right. I have four
instance variables, which are blocks which execute whenever the state
changes:
onRightAction <BlockContext> or nil
offRightAction <BlockContext> or nil
onLeftAction <BlockContext> or nil
offLeftAction <BlockContext> or nil
leftChar <Character> for moving left
rightChar <Character> for moving right'!
!TwoWayHorizJoystick methodsFor: 'initialize-release'!
release
"Set all the actions of the receiver to nil ('no action') in order to break
possible pointer cycles. It is sent by Joystick|removeDependent: when the
last dependent has been deleted from the Joystick's list of dependents."
super release.
leftOnAction _ nil.
leftOffAction _ nil.
rightOnAction _ nil.
rightOffAction _ nil.! !
!TwoWayHorizJoystick methodsFor: 'accessing'!
leftChar: aCharacter
"Set the 'left' character to aCharacter."
leftChar _ aCharacter!
rightChar: aCharacter
"Set the 'right' character to aCharacter."
rightChar _ aCharacter! !
!TwoWayHorizJoystick methodsFor: 'state changes'!
goLeft
"Set the state of the receiver to #left and perform the `left on'
action. If the receiver was not #left, then change any dependents."
self doAction: leftOnAction.
self isLeft ifFalse: [state _ #left. self changed]!
goRight
"Set the state of the receiver to #right and perform the `right on'
action. If the receiver was not #right, then change any dependents."
self doAction: rightOnAction.
self isRight ifFalse: [state _ #right. self changed]!
goToLeft
"Return to the #off position, and then move to #left."
self return.
self goLeft.!
goToRight
"Return to the #off position, and then move to #right."
self return.
self goRight.!
moveAngle: anAngle
"The angle between the joystick center and the cursor position is
anAngle, relative to the x-axis. Move appropriately."
(anAngle between: 135 and: 225)
ifTrue: [self isLeft ifTrue: [^self goLeft] ifFalse: [^self goToLeft]].
((anAngle between: 315 and: 360) or: [anAngle between: 0 and: 45])
ifTrue: [self isRight ifTrue: [^self goRight] ifFalse: [^self goToRight]]!
moveCharacter: aCharacter
"Execute the block selected by aCharacter (from the user)."
aCharacter == leftChar ifTrue: [self goLeft. ^self return].
aCharacter == rightChar ifTrue: [self goRight. ^self return].
super moveCharacter: aCharacter!
return
"Set the state of the receiver to #off and perform the appropriate
off action. If the receiver was not previously off, update any dependents."
self isRight ifTrue: [self doAction: rightOffAction].
self isLeft ifTrue: [self doAction: leftOffAction].
self isOff ifFalse: [state _ #off. self changed]! !
!TwoWayHorizJoystick methodsFor: 'action'!
leftOffAction: aBlock
"Set the left, off action of the receiver to aBlock."
leftOffAction _ aBlock fixTemps!
leftOnAction: aBlock
"Set the left, on action of the receiver to aBlock."
leftOnAction _ aBlock fixTemps!
rightOffAction: aBlock
"Set the right, off action of the receiver to aBlock."
rightOffAction _ aBlock fixTemps!
rightOnAction: aBlock
"Set the right, on action of the receiver to aBlock."
rightOnAction _ aBlock fixTemps! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
TwoWayHorizJoystick class
instanceVariableNames: ''!
!TwoWayHorizJoystick class methodsFor: 'instance creation'!
leftAction: leftBlock rightAction: rightBlock
"Answer with a new instance of the receiver, which evaluates
leftBlock when moved left, and rightBlock when moved right."
| temp |
temp _ super new leftOnAction: leftBlock.
temp rightOnAction: rightBlock.
^temp! !
!TwoWayHorizJoystick class methodsFor: 'examples'!
example1
"Illustrates basic action of a TwoWayHorizJoystick."
"TwoWayHorizJoystick example1."
| j |
j _ TwoWayHorizJoystick
leftAction: [Transcript cr; show: 'Going left.']
rightAction: [Transcript cr; show: 'Going right.'].
j goToLeft.
j goToRight.
j return!
example2
"Illustrates use of TwoWayHorizJoystick with simple view and normal
(non-auto-repeat) controller. No 'off' actions."
"TwoWayHorizJoystick example2."
| view topView joystick |
joystick _ TwoWayHorizJoystick
leftAction: [Transcript cr; show: 'Going left.']
rightAction: [Transcript cr; show: 'Going right.'].
view _ JoystickView new model: joystick.
topView _ StandardSystemView
model: nil
label: 'Horizontal Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open!
example3
"This example uses an 'auto-repeat' controller."
"TwoWayHorizJoystick example3."
| view topView joystick |
joystick _ TwoWayHorizJoystick
leftAction: [Transcript cr; show: 'Going left.']
rightAction: [Transcript cr; show: 'Going right.'].
view _ JoystickView new
model: joystick
controller: RepeatJoystickController new.
topView _ StandardSystemView
model: nil
label: 'Horizontal Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open!
example4
"This example uses an 'auto-repeat' controller, 'off' actions, and
the view has a coloured background."
"TwoWayHorizJoystick example4."
| view topView joystick |
joystick _ TwoWayHorizJoystick
leftAction: [Transcript cr; show: 'Going left...']
rightAction: [Transcript cr; show: 'Going right...'].
joystick leftOffAction: [Transcript show: 'back to center'].
joystick rightOffAction: [Transcript show: 'back to center'].
view _ JoystickView new
model: joystick
controller: RepeatJoystickController new.
view insideColor: Form veryLightGray.
topView _ StandardSystemView
model: nil
label: 'Horizontal Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open!
example5
"Illustrates use of TwoWayHorizJoystick with simple view and normal
(non-auto-repeat) controller. Uses character input ('rogue'-style)."
"TwoWayHorizJoystick example5."
| view topView joystick |
joystick _ TwoWayHorizJoystick
leftAction: [Transcript cr; show: 'Going left.']
rightAction: [Transcript cr; show: 'Going right.'].
joystick leftChar: $h.
joystick rightChar: $l.
view _ JoystickView new model: joystick.
topView _ StandardSystemView
model: nil
label: 'Horizontal Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open! !
Joystick subclass: #DiagonalJoystick
instanceVariableNames: 'upRightOnAction upRightOffAction upLeftOnAction upLeftOffAction downLeftOnAction downLeftOffAction downRightOnAction downRightOffAction upRightChar upLeftChar downLeftChar downRightChar '
classVariableNames: ''
poolDictionaries: ''
category: 'Interface-Joysticks'!
DiagonalJoystick comment:
'I am a Joystick subclass which represents movement in four diagonal directions.
My instance variables are:
upRightOnAction <BlockContext> or nil
upRightOffAction <BlockContext> or nil
upLeftOnAction <BlockContext> or nil
upLeftOffAction <BlockContext> or nil
downLeftOnAction <BlockContext> or nil
downLeftOffAction <BlockContext> or nil
downRightOnAction <BlockContext> or nil
downRightOffAction <BlockContext> or nil
upRightChar <Character> for moving up-and-right
upLeftChar <Character> for moving up-and-left
downRightChar <Character> for moving down-and-right
downLeftChar <Character> for moving down-and-left
'!
!DiagonalJoystick methodsFor: 'initialize-release'!
release
"Set all the actions of the receiver to nil ('no action') in order to break
possible pointer cycles. It is sent by Joystick|removeDependent: when the
last dependent has been deleted from the Joystick's list of dependents."
super release.
upLeftOnAction _ nil.
upLeftOffAction _ nil.
downLeftOnAction _ nil.
downLeftOffAction _ nil.
upRightOnAction _ nil.
upRightOffAction _ nil.
downRightOnAction _ nil.
downRightOffAction _ nil.! !
!DiagonalJoystick methodsFor: 'accessing'!
downLeftChar: aCharacter
"Set the 'down-and-left' character to aCharacter."
downLeftChar _ aCharacter!
downRightChar: aCharacter
"Set the 'down-and-right' character to aCharacter."
downRightChar _ aCharacter!
upLeftChar: aCharacter
"Set the 'up-and-left' character to aCharacter."
upLeftChar _ aCharacter!
upRightChar: aCharacter
"Set the 'up-and-right' character to aCharacter."
upRightChar _ aCharacter! !
!DiagonalJoystick methodsFor: 'state changes'!
goDownLeft
"Set the state of the receiver to #leftDown and perform the `down-and-left
on' action. If the receiver was not #leftDown, then change any dependents."
self doAction: downLeftOnAction.
self isDownLeft ifFalse: [state _ #leftDown. self changed]!
goDownRight
"Set the state of the receiver to #rightDown and perform the `down-and-right
on' action. If the receiver was not #rightDown, then change any dependents."
self doAction: downRightOnAction.
self isDownRight ifFalse: [state _ #rightDown. self changed]!
goToDownLeft
"Return to the #off position, and then move to down-and-left."
self return.
self goDownLeft.!
goToDownRight
"Return to the #off position, and then move to down-and-right."
self return.
self goDownRight.!
goToUpLeft
"Return to the #off position, and then move to up-and-left."
self return.
self goUpLeft.!
goToUpRight
"Return to the #off position, and then move to up-and-right."
self return.
self goUpRight.!
goUpLeft
"Set the state of the receiver to #leftUp and perform the `up-and-left
on' action. If the receiver was not #leftUp, then change any dependents."
self doAction: upLeftOnAction.
self isUpLeft ifFalse: [state _ #leftUp. self changed]!
goUpRight
"Set the state of the receiver to #rightUp and perform the `up-and-right
on' action. If the receiver was not #rightUp, then change any dependents."
self doAction: upRightOnAction.
self isUpRight ifFalse: [state _ #rightUp. self changed]!
moveAngle: anAngle
"The angle between the joystick center and the cursor position is
anAngle, relative to the x-axis. Move appropriately."
(anAngle between: 0 and: 90)
ifTrue: [self isDownRight ifTrue: [^self goDownRight] ifFalse: [^self goToDownRight]].
(anAngle between: 90 and: 180)
ifTrue: [self isDownLeft ifTrue: [^self goDownLeft] ifFalse: [^self goToDownLeft]].
(anAngle between: 180 and: 270)
ifTrue: [self isUpLeft ifTrue: [^self goUpLeft] ifFalse: [^self goToUpLeft]].
self isUpRight ifTrue: [^self goUpRight] ifFalse: [^self goToUpRight]!
moveCharacter: aCharacter
"Execute the block selected by aCharacter (from the user)."
aCharacter == upLeftChar ifTrue: [self goUpLeft. ^self return].
aCharacter == downLeftChar ifTrue: [self goDownLeft. ^self return].
aCharacter == upRightChar ifTrue: [self goUpRight. ^self return].
aCharacter == downRightChar ifTrue: [self goDownRight. ^self return].
super moveCharacter: aCharacter!
return
"Set the state of the receiver to #off and perform the appropriate
off action. If the receiver was not previously off, update any
dependents. "
self isUpLeft ifTrue: [self doAction: upLeftOffAction].
self isUpRight ifTrue: [self doAction: upRightOffAction].
self isDownLeft ifTrue: [self doAction: downLeftOffAction].
self isDownRight ifTrue: [self doAction: downRightOffAction].
self isOff ifFalse: [state _ #off. self changed]! !
!DiagonalJoystick methodsFor: 'action'!
downLeftOffAction: aBlock
"Set the down, left, off action of the receiver to aBlock."
downLeftOffAction _ aBlock fixTemps!
downLeftOnAction: aBlock
"Set the down, left, on action of the receiver to aBlock."
downLeftOnAction _ aBlock fixTemps!
downRightOffAction: aBlock
"Set the down, right, off action of the receiver to aBlock."
downRightOffAction _ aBlock fixTemps!
downRightOnAction: aBlock
"Set the down, right, on action of the receiver to aBlock."
downRightOnAction _ aBlock fixTemps!
upLeftOffAction: aBlock
"Set the up, left, off action of the receiver to aBlock."
upLeftOffAction _ aBlock fixTemps!
upLeftOnAction: aBlock
"Set the up, left, on action of the receiver to aBlock."
upLeftOnAction _ aBlock fixTemps!
upRightOffAction: aBlock
"Set the up, right, off action of the receiver to aBlock."
upRightOffAction _ aBlock fixTemps!
upRightOnAction: aBlock
"Set the up, right, on action of the receiver to aBlock."
upRightOnAction _ aBlock fixTemps! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
DiagonalJoystick class
instanceVariableNames: ''!
!DiagonalJoystick class methodsFor: 'instance creation'!
downLeftAction: downLeftBlock downRightAction: downRightBlock upLeftAction: upLeftBlock upRightAction: upRightBlock
"Answer with a new instance of the receiver, which evaluates
downLeftBlock when moved down-and-left, downRightBlock when
moved down-and-right, upLeftBlock when moved up-and-left and
upRightBlock when moved up-and-right."
| temp |
temp _ self new downLeftOnAction: downLeftBlock.
temp downRightOnAction: downRightBlock.
temp upRightOnAction: upRightBlock.
temp upLeftOnAction: upLeftBlock.
^temp! !
!DiagonalJoystick class methodsFor: 'examples'!
example1
"Illustrates basic action of a DiagonalJoystick."
"DiagonalJoystick example1."
| j |
j _ DiagonalJoystick
downLeftAction: [Transcript cr; show: 'Going left and down.']
downRightAction: [Transcript cr; show: 'Going right and down']
upLeftAction: [Transcript cr; show: 'Going left and up.']
upRightAction: [Transcript cr; show: 'Going right and up.'].
j goToDownLeft.
j goToDownRight.
j return.
j goToUpLeft.
j goToUpRight.
j return!
example2
"Illustrates use of DiagonalJoystick with simple view and
normal controller. No 'off' actions."
"DiagonalJoystick example2."
| view topView joystick |
joystick _ DiagonalJoystick
downLeftAction: [Transcript cr; show: 'Going down-and-left.']
downRightAction: [Transcript cr; show: 'Going down-and-right.']
upLeftAction: [Transcript cr; show: 'Going up-and-left.']
upRightAction: [Transcript cr; show: 'Going up-and-right.'].
view _ JoystickView new model: joystick.
topView _ StandardSystemView
model: nil
label: 'Diagonal Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open!
example3
"Illustrates use of DiagonalJoystick with simple view and
auto-repeat controller. No 'off' actions."
"DiagonalJoystick example3."
| view topView joystick |
joystick _ DiagonalJoystick
downLeftAction: [Transcript cr; show: 'Going down-and-left.']
downRightAction: [Transcript cr; show: 'Going down-and-right.']
upLeftAction: [Transcript cr; show: 'Going up-and-left.']
upRightAction: [Transcript cr; show: 'Going up-and-right.'].
view _ JoystickView new
model: joystick
controller: RepeatJoystickController new.
topView _ StandardSystemView
model: nil
label: 'Diagonal Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open!
example4
"This example uses an 'auto-repeat' controller, 'off' actions, and
the view has a coloured background."
"DiagonalJoystick example4."
| view topView joystick |
joystick _ DiagonalJoystick
downLeftAction: [Transcript cr; show: 'Going down-and-left... ']
downRightAction: [Transcript cr; show: 'Going down-and-right... ']
upLeftAction: [Transcript cr; show: 'Going up-and-left... ']
upRightAction: [Transcript cr; show: 'Going up-and-right... '].
joystick downLeftOffAction: [Transcript show: 'back to center'].
joystick downRightOffAction: [Transcript show: 'back to center'].
joystick upLeftOffAction: [Transcript show: 'back to center'].
joystick upRightOffAction: [Transcript show: 'back to center'].
view _ JoystickView new
model: joystick
controller: RepeatJoystickController new.
view insideColor: Form veryLightGray.
topView _ StandardSystemView
model: nil
label: 'Diagonal Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open!
example5
"Illustrates use of FourWayJoystick with simple view and normal
(non-auto-repeat) controller. Demonstrates 'rogue'-style key-bindings."
"DiagonalJoystick example5."
| view topView joystick |
joystick _ DiagonalJoystick
downLeftAction: [Transcript cr; show: 'Going down-and-left.']
downRightAction: [Transcript cr; show: 'Going down-and-right.']
upLeftAction: [Transcript cr; show: 'Going up-and-left.']
upRightAction: [Transcript cr; show: 'Going up-and-right.'].
joystick downLeftChar: $b.
joystick downRightChar: $n.
joystick upLeftChar: $y.
joystick upRightChar: $u.
view _ JoystickView new model: joystick.
topView _ StandardSystemView
model: nil
label: 'Diagonal Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open! !
TwoWayHorizJoystick subclass: #FourWayJoystick
instanceVariableNames: 'upOnAction upOffAction downOnAction downOffAction upChar downChar '
classVariableNames: ''
poolDictionaries: ''
category: 'Interface-Joysticks'!
FourWayJoystick comment:
'I am a Joystick subclass which represents movement in all four directions.
My instance variables are:
onUpAction <BlockContext> or nil
offUpAction <BlockContext> or nil
onDownAction <BlockContext> or nil
offDownAction <BlockContext> or nil
upChar <Character> for moving up
downChar <Character> for moving down
Ideally, I would be a subclass of both TwoWayHorizJoystick and
TwoWayVertJoystick, but this doesn''t work very well in Smalltalk. I did
actually try this, but it was so slow that I re-arranged things to
the present structure.'!
!FourWayJoystick methodsFor: 'initialize-release'!
release
"Set all the actions of the receiver to nil ('no action') in order to break
possible pointer cycles. It is sent by Joystick|removeDependent: when the
last dependent has been deleted from the Joystick's list of dependents."
super release.
upOnAction _ nil.
upOffAction _ nil.
downOnAction _ nil.
downOffAction _ nil.! !
!FourWayJoystick methodsFor: 'accessing'!
downChar: aCharacter
"Set the 'down' character to aCharacter."
downChar _ aCharacter!
upChar: aCharacter
"Set the 'up' character to aCharacter."
upChar _ aCharacter! !
!FourWayJoystick methodsFor: 'state changes'!
goDown
"Set the state of the receiver to #down and perform the `down on'
action. If the receiver was not #down, then change any dependents."
self doAction: downOnAction.
self isDown ifFalse: [state _ #down. self changed]!
goToDown
"Return to the #off position, and then move to #down."
self return.
self goDown.!
goToUp
"Return to the #off position, and then move to #up."
self return.
self goUp.!
goUp
"Set the state of the receiver to #up and perform the `up on'
action. If the receiver was not #up, then change any dependents."
self doAction: upOnAction.
self isUp ifFalse: [state _ #up. self changed]!
moveAngle: anAngle
"The angle between the joystick center and the cursor position is
anAngle, relative to the x-axis. Move appropriately."
(anAngle between: 45 and: 135)
ifTrue: [self isDown ifTrue: [^self goDown] ifFalse: [^self goToDown]].
(anAngle between: 135 and: 225)
ifTrue: [self isLeft ifTrue: [^self goLeft] ifFalse: [^self goToLeft]].
(anAngle between: 225 and: 315)
ifTrue: [self isUp ifTrue: [^self goUp] ifFalse: [^self goToUp]].
self isRight ifTrue: [^self goRight] ifFalse: [^self goToRight]!
moveCharacter: aCharacter
"Execute the block selected by aCharacter (from the user)."
aCharacter == upChar ifTrue: [self goUp. ^self return].
aCharacter == downChar ifTrue: [self goDown. ^self return].
super moveCharacter: aCharacter!
return
"Set the state of the receiver to #off and perform the appropriate
off action. If the receiver was not previously off, update any dependents."
self isUp ifTrue: [self doAction: upOffAction].
self isDown ifTrue: [self doAction: downOffAction].
super return! !
!FourWayJoystick methodsFor: 'action'!
downOffAction: aBlock
"Set the down, off action of the receiver to aBlock."
downOffAction _ aBlock fixTemps!
downOnAction: aBlock
"Set the down, on action of the receiver to aBlock."
downOnAction _ aBlock fixTemps!
upOffAction: aBlock
"Set the up, off action of the receiver to aBlock."
upOffAction _ aBlock fixTemps!
upOnAction: aBlock
"Set the up, on action of the receiver to aBlock."
upOnAction _ aBlock fixTemps! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
FourWayJoystick class
instanceVariableNames: ''!
!FourWayJoystick class methodsFor: 'instance creation'!
leftAction: leftBlock rightAction: rightBlock upAction: upBlock downAction: downBlock
"Answer with a new instance of the receiver, which evaluates
leftBlock when moved left, rightBlock when moved right, upBlock
when moved up and downBlock when moved down."
| temp |
temp _ self leftAction: leftBlock rightAction: rightBlock.
temp upOnAction: upBlock.
temp downOnAction: downBlock.
^temp! !
!FourWayJoystick class methodsFor: 'examples'!
example1
"Illustrates basic action of a FourWayJoystick."
"FourWayJoystick example1."
| j |
j _ FourWayJoystick
leftAction: [Transcript cr; show: 'Going left.']
rightAction: [Transcript cr; show: 'Going right.']
upAction: [Transcript cr; show: 'Going up.']
downAction: [Transcript cr; show: 'Going down.'].
j goToLeft.
j goToRight.
j return.
j goToUp.
j goToDown.
j return!
example2
"Illustrates use of FourWayJoystick with simple view and normal
(non-auto-repeat) controller. No 'off' actions."
"FourWayJoystick example2."
| view topView joystick |
joystick _ FourWayJoystick
leftAction: [Transcript cr; show: 'Going left.']
rightAction: [Transcript cr; show: 'Going right.']
upAction: [Transcript cr; show: 'Going up.']
downAction: [Transcript cr; show: 'Going down.'].
view _ JoystickView new model: joystick.
topView _ StandardSystemView
model: nil
label: 'Four-Way Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open!
example3
"This example uses an 'auto-repeat' controller."
"FourWayJoystick example3."
| view topView joystick |
joystick _ FourWayJoystick
leftAction: [Transcript cr; show: 'Going left.']
rightAction: [Transcript cr; show: 'Going right.']
upAction: [Transcript cr; show: 'Going up.']
downAction: [Transcript cr; show: 'Going down.'].
view _ JoystickView new
model: joystick
controller: RepeatJoystickController new.
topView _ StandardSystemView
model: nil
label: 'Four-way Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open!
example4
"This example uses an 'auto-repeat' controller, 'off' actions, and
the view has a coloured background."
"FourWayJoystick example4."
| view topView joystick |
joystick _ FourWayJoystick
leftAction: [Transcript cr; show: 'Going left...']
rightAction: [Transcript cr; show: 'Going right...']
upAction: [Transcript cr; show: 'Going up...']
downAction: [Transcript cr; show: 'Going down...'].
joystick leftOffAction: [Transcript show: 'back to center'].
joystick rightOffAction: [Transcript show: 'back to center'].
joystick upOffAction: [Transcript show: 'back to center'].
joystick downOffAction: [Transcript show: 'back to center'].
view _ JoystickView new
model: joystick
controller: RepeatJoystickController new.
view insideColor: Form veryLightGray.
topView _ StandardSystemView
model: nil
label: 'Four-way Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open!
example5
"Illustrates use of FourWayJoystick with simple view and normal
(non-auto-repeat) controller. Demonstrates 'rogue'-style key-bindings."
"FourWayJoystick example5."
| view topView joystick |
joystick _ FourWayJoystick
leftAction: [Transcript cr; show: 'Going left.']
rightAction: [Transcript cr; show: 'Going right.']
upAction: [Transcript cr; show: 'Going up.']
downAction: [Transcript cr; show: 'Going down.'].
joystick upChar: $k.
joystick downChar: $j.
joystick leftChar: $h.
joystick rightChar: $l.
view _ JoystickView new model: joystick.
topView _ StandardSystemView
model: nil
label: 'Four-Way Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open! !
FourWayJoystick subclass: #EightWayJoystick
instanceVariableNames: 'upLeftChar upRightChar downLeftChar downRightChar '
classVariableNames: ''
poolDictionaries: ''
category: 'Interface-Joysticks'!
EightWayJoystick comment:
'I am a Joystick subclass which understands movement in eight directions.
In fact, I execute (for example) both the ''up'' and ''left'' blocks (defined
in my superclases) when I am positioned ''up-and-left''. My instance
variables are:
upLeftChar <Character> for moving up-and-left
upRightChar <Character> for moving up-and-right
downLeftChar <Character> for moving down-and-left
downRightChar <Character> for moving down-and-right
'!
!EightWayJoystick methodsFor: 'accessing'!
downLeftChar: aCharacter
"Set the 'down-and-left' character to aCharacter."
downLeftChar _ aCharacter!
downRightChar: aCharacter
"Set the 'down-and-right' character to aCharacter."
downRightChar _ aCharacter!
upLeftChar: aCharacter
"Set the 'up-and-left' character to aCharacter."
upLeftChar _ aCharacter!
upRightChar: aCharacter
"Set the 'up-and-right' character to aCharacter."
upRightChar _ aCharacter! !
!EightWayJoystick methodsFor: 'state changes'!
goDownLeft
"Set the state of the receiver to #leftDown and perform the `down-and-left on'
action. If the receiver was not #leftDown, then change any dependents."
self doAction: leftOnAction.
self doAction: downOnAction.
self isDownLeft ifFalse: [state _ #leftDown. self changed]!
goDownRight
"Set the state of the receiver to #rightDown and perform the
`down-and-right on' action. If the receiver was not #rightDown,
then change any dependents. "
self doAction: rightOnAction.
self doAction: downOnAction.
self isDownRight ifFalse: [state _ #rightDown. self changed]!
goToDownLeft
"Return to the #off position, and then move to down-and-left."
self return.
self goDownLeft.!
goToDownRight
"Return to the #off position, and then move to down-and-right."
self return.
self goDownRight.!
goToUpLeft
"Return to the #off position, and then move to up-and-left."
self return.
self goUpLeft.!
goToUpRight
"Return to the #off position, and then move to up-and-right."
self return.
self goUpRight.!
goUpLeft
"Set the state of the receiver to #leftUp and perform the `up-and-left on'
action. If the receiver was not #leftUp, then change any dependents."
self doAction: leftOnAction.
self doAction: upOnAction.
self isUpLeft ifFalse: [state _ #leftUp. self changed]!
goUpRight
"Set the state of the receiver to #rightUp and perform the `up-and-right on'
action. If the receiver was not #rightUp, then change any dependents."
self doAction: rightOnAction.
self doAction: upOnAction.
self isUpRight ifFalse: [state _ #rightUp. self changed]!
moveAngle: anAngle
"The angle between the joystick center and the cursor position is
anAngle, relative to the x-axis. Move appropriately."
(anAngle between: 23 and: 67) ifTrue: [
self isDownRight ifTrue: [^self goDownRight] ifFalse: [^self goToDownRight]].
(anAngle between: 67 and: 112) ifTrue: [
self isDown ifTrue: [^self goDown] ifFalse: [^self goToDown]].
(anAngle between: 112 and: 157) ifTrue: [
self isDownLeft ifTrue: [^self goDownLeft] ifFalse: [^self goToDownLeft]].
(anAngle between: 157 and: 202) ifTrue: [
self isLeft ifTrue: [^self goLeft] ifFalse: [^self goToLeft]].
(anAngle between: 202 and: 247) ifTrue: [
self isUpLeft ifTrue: [^self goUpLeft] ifFalse: [^self goToUpLeft]].
(anAngle between: 247 and: 292) ifTrue: [
self isUp ifTrue: [^self goUp] ifFalse: [^self goToUp]].
(anAngle between: 292 and: 337) ifTrue: [
self isUpRight ifTrue: [^self goUpRight] ifFalse: [^self goToUpRight]].
self isRight ifTrue: [^self goRight] ifFalse: [^self goToRight]!
moveCharacter: aCharacter
"Execute the block selected by aCharacter (from the user)."
aCharacter == upLeftChar ifTrue: [self goUpLeft. ^self return].
aCharacter == downLeftChar ifTrue: [self goDownLeft. ^self return].
aCharacter == upRightChar ifTrue: [self goUpRight. ^self return].
aCharacter == downRightChar ifTrue: [self goDownRight. ^self return].
super moveCharacter: aCharacter!
return
"Set the state of the receiver to #off and perform the appropriate
off action. If the receiver was not previously off, update any
dependents. "
self isUpLeft ifTrue: [
self doAction: upOffAction.
self doAction: leftOffAction].
self isUpRight ifTrue: [
self doAction: upOffAction.
self doAction: rightOffAction].
self isDownLeft ifTrue: [
self doAction: downOffAction.
self doAction: leftOffAction].
self isDownRight ifTrue: [
self doAction: downOffAction.
self doAction: rightOffAction].
super return! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
EightWayJoystick class
instanceVariableNames: ''!
!EightWayJoystick class methodsFor: 'examples'!
example1
"Illustrates basic action of an EightWayJoystick."
"EightWayJoystick example1."
| j |
j _ EightWayJoystick
leftAction: [Transcript cr; show: 'Going left.']
rightAction: [Transcript cr; show: 'Going right.']
upAction: [Transcript cr; show: 'Going up.']
downAction: [Transcript cr; show: 'Going down.'].
j goToUpRight.
j return.
j goToDownLeft.
j return.
j goToDown!
example2
"Illustrates use of EightWayJoystick with simple view and normal
(non-auto-repeat) controller. No 'off' actions."
"EightWayJoystick example2."
| view topView joystick |
joystick _ EightWayJoystick
leftAction: [Transcript cr; show: 'Going left.']
rightAction: [Transcript cr; show: 'Going right.']
upAction: [Transcript cr; show: 'Going up.']
downAction: [Transcript cr; show: 'Going down.'].
view _ JoystickView new model: joystick.
topView _ StandardSystemView
model: nil
label: 'Eight-way Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open!
example3
"This example uses an 'auto-repeat' controller."
"EightWayJoystick example3."
| view topView joystick |
joystick _ EightWayJoystick
leftAction: [Transcript cr; show: 'Going left.']
rightAction: [Transcript cr; show: 'Going right.']
upAction: [Transcript cr; show: 'Going up.']
downAction: [Transcript cr; show: 'Going down.'].
view _ JoystickView new
model: joystick
controller: RepeatJoystickController new.
topView _ StandardSystemView
model: nil
label: 'Eight-way Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open!
example4
"This example uses an 'auto-repeat' controller, 'off' actions, and
the view has a coloured background."
"EightWayJoystick example4."
| view topView joystick |
joystick _ EightWayJoystick
leftAction: [Transcript cr; show: 'Going left...']
rightAction: [Transcript cr; show: 'Going right...']
upAction: [Transcript cr; show: 'Going up...']
downAction: [Transcript cr; show: 'Going down...'].
joystick leftOffAction: [Transcript show: 'back to center '].
joystick rightOffAction: [Transcript show: 'back to center '].
joystick upOffAction: [Transcript show: 'back to center '].
joystick downOffAction: [Transcript show: 'back to center '].
view _ JoystickView new
model: joystick
controller: RepeatJoystickController new.
view insideColor: Form veryLightGray.
topView _ StandardSystemView
model: nil
label: 'Eight-way Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open!
example5
"Illustrates use of EightWayJoystick with simple view and normal
(non-auto-repeat) controller. Uses 'rogue'-style key-bindings."
"EightWayJoystick example5."
| view topView joystick |
joystick _ EightWayJoystick
leftAction: [Transcript cr; show: 'Going left.']
rightAction: [Transcript cr; show: 'Going right.']
upAction: [Transcript cr; show: 'Going up.']
downAction: [Transcript cr; show: 'Going down.'].
joystick leftChar: $h.
joystick upLeftChar: $y.
joystick upChar: $k.
joystick upRightChar: $u.
joystick rightChar: $l.
joystick downRightChar: $n.
joystick downChar: $j.
joystick downLeftChar: $b.
view _ JoystickView new model: joystick.
topView _ StandardSystemView
model: nil
label: 'Eight-way Joystick'
minimumSize: 55 @ 55.
topView borderWidth: 2.
topView addSubView: view.
topView controller open! ! topView controller open! !